// pages/xinZengDan/order1/order.js
const app = getApp()
const utils = require("../../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderCheck: null,
    username: null,
    stepsIndex: 0,
    stepItemCount: 4,
    stepItemContent: [],
    stepItemContent2: [],
    activeValues1: 0,
    activeValues2: 0,
    activeValues3: 0,
    activeValues4: 0,
    mode: '',
    datetimeVisible: false,
    datetime: new Date().getTime(),
    datetimeText: utils.formatTime(new Date()),
    danhao: "",
    xiangmuName: null,
    shouhuoDizhi: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      orderCheck: options.key,
      username: options.userName,
      stepItemCount: app.globalData.stepItemCount,
      stepItemContent: app.globalData.stepItemContent,
      stepItemContent2: app.globalData.stepItemContent2
    })
  },
  handleChange(e) {
    var key = e.currentTarget.dataset.type
    switch (key) {
      case "1":
        this.setData({
          activeValues1: e.detail.value,
        });
        break;
      case "2":
        this.setData({
          activeValues2: e.detail.value,
        });
        break;
      case "3":
        this.setData({
          activeValues3: e.detail.value,
        });
        break;
      case "4":
        this.setData({
          activeValues4: e.detail.value,
        });
        break;
      default:
        break;
    }
  },
  showPicker(e) {
    const { mode } = e?.currentTarget?.dataset;
    this.setData({
      mode,
      [`${mode}Visible`]: true,
    });
  },
  hidePicker() {
    const { mode } = this.data;
    this.setData({
      [`${mode}Visible`]: false,
    });
  },
  onConfirm(e) {
    const { value } = e?.detail;
    const { mode } = this.data;

    // console.log('confirm', value);

    this.setData({
      [mode]: value,
      [`${mode}Text`]: value,
    });

    this.hidePicker();
  },

  onColumnChange(e) {
    console.log('pick', e?.detail?.value);
  },
  toPageTwo: function () {
    var that = this
    if (this.data.orderCheck == 1) {
      app.globalData.order = {
        xiadanriqi: that.data.datetime,
        shouhuodizhi: that.data.shouhuoDizhi,
        yewuyuan: that.data.username,
        xiangmumingcheng: null,
        fahuoren: null,
        wujinpeitao: null,
        beizhu: null,
        zongjine: null,
        shangpin: []
      }
    } else {
      app.globalData.order = {
        danhao: that.data.danhao,
        xiadanriqi: that.data.datetime,
        xiangmumingcheng: that.data.xiangmuName,
        shouhuodizhi: that.data.shouhuoDizhi,
        yewuyuan: that.data.username,
        fahuoren: null,
        wujinpeitao: null,
        beizhu: null,
        zongjine: null,
        shangpin: []
      }
    }
    wx.navigateTo({
      url: '/pages/xinZengDan/order2/order?key=' + this.data.orderCheck + '&username=' + this.data.username,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})